{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2f9035c5-a0fb-4b22-b9a7-0c2b22a5ba3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: numpy in d:\\programdata\\anaconda3\\lib\\site-packages (1.26.4)\n"
     ]
    }
   ],
   "source": [
    "!pip install numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f41833a9-b570-4634-b56c-f7a2ab1ede26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w= [[-0.71195672  0.62359524]] b= [0.591986]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "x=np.array([[2,3],[3,4],[6,5],[4,4],[3,2],[4,7],[5,4],[4,3],[7,5],[3,3],[4,4],[5,2]])\n",
    "y=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "model=LogisticRegression()\n",
    "model.fit(x,y.ravel())\n",
    "print(\"w=\",model.coef_,\"b=\",model.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "16181a1b-8587-4a6f-8862-e265d29d4870",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型预测准确率为： 0.75\n"
     ]
    }
   ],
   "source": [
    "x_test=np.array([[3,5],[2,4],[5,6],[3,6],[3,3],[4,5],[4,2],[5,5],[6,7],[5,3],[6,4],[6,6]])\n",
    "y_test=np.array([[1],[1],[1],[1],[1],[1],[0],[0],[0],[0],[0],[0]])\n",
    "r2=model.score(x_test,y_test)\n",
    "print(\"模型预测准确率为：\",r2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3dfaef68-3874-4f65-ab56-074b75e77b49",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "新样本预测标签为： 1\n"
     ]
    }
   ],
   "source": [
    "a=model.predict([[3,7]])\n",
    "print(\"新样本预测标签为：\",a[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "268675e9-d860-4d19-a190-d9147ba70b9c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
